`
https://leetcode.cn/problems/minimum-ascii-delete-sum-for-two-strings/
`

/**
 * @param {string} s1
 * @param {string} s2
 * @return {number}
 */
var minimumDeleteSum = function (s1, s2) {
  // 该题只是 https://leetcode.cn/problems/delete-operation-for-two-strings/ 的变种
  const m = s1.length, n = s2.length

  const memo = Array.from({ length: m }, () => new Array(n).fill(-1))

  function dp(i, j) {
    let res = 0
    if (i === s1.length) {
      // 如果 s1 到头了，那么 s2 剩下的都得删除
      for (; j < s2.length; j++) {
        res += s2.charCodeAt(j)
      }
      return res
    }
    if (j === s2.length) {
      // 如果 s2 到头了，那么 s1 剩下的都得删除
      for (; i < s1.length; i++) {
        res += s1.charCodeAt(i)
      }
      return res
    }

    // 如果已经计算过了
    if (memo[i][j] !== -1) {
      return memo[i][j]
    }

    // 两个字符相同跳过，不用删
    if (s1[i] === s2[j]) {
      memo[i][j] = dp(i + 1, j + 1)
    } else {
      memo[i][j] = Math.min(
        // 删 s1[i]
        s1.charCodeAt(i) + dp(i + 1, j),
        // 删 s2[j]
        s2.charCodeAt(j) + dp(i, j + 1)
      )
    }

    return memo[i][j]
  }

  return dp(0, 0)
};